package com.jala.base;

import com.jala.cm.BizException;
import com.jala.cm.Paginator;
import com.jala.ecs.client.auth.Principal;
import com.jala.ecs.client.codedict.client.CodeDictClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/cacheReload")
public class ClearCachesAction extends BaseAction {
	
	private final Logger log=LoggerFactory.getLogger(ClearCachesAction.class);
	
	@Autowired
	private Principal principal;
	
	@Autowired
	private CodeDictClient codeDictClient;
	
	@RequestMapping(value="/info.htm",method=RequestMethod.GET)
	public String cacheReloadInfo(HttpServletRequest req, Paginator page, ModelMap model) throws BizException{
		log.info("commomAction cacheReload info begin ....");
		
		return "admin/cacheReloadInfo";	
	}
	
	@RequestMapping(value="/clear.json",method=RequestMethod.POST)
	public String postCacheReloadInfo(HttpServletRequest req, Paginator page, ModelMap model) throws BizException{
		log.info("commomAction cacheReload clear begin ....");
		
		//清空所有缓存
		principal.clearAllCache();
		
		//清除当前用户的缓存
		principal.clearCache();
		
		//清除数据字典缓存
		codeDictClient.reload();
		
		return "json";	
	}
	
}
